package com.example.xiaoxing.lashou;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.xiaoxing.lashou.fragment.fragmentIndex;
import com.example.xiaoxing.lashou.fragment.fragmentMore;
import com.example.xiaoxing.lashou.fragment.fragmentMy;
import com.example.xiaoxing.lashou.fragment.fragmentNearby;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnRadioGroupCheckedChange;

public class MainActivity extends FragmentActivity {
    @ViewInject(R.id.Botton_bar)
    private RadioGroup Botton_bar;
    @ViewInject(R.id.content)
    private FrameLayout content;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ViewUtils.inject(this);
    }
    @OnRadioGroupCheckedChange(R.id.Botton_bar)
    public void onCheckchanged(RadioGroup group,int checkedId){
          int index=0;
        switch (checkedId){
            case R.id.radioButton1:
                index=0;
                break;
            case R.id.radioButton2:
                index=1;
                break;
            case R.id.radioButton3:
                index=2;
                break;
            case R.id.radioButton4:
                index=3;
                break;
        }
        Fragment fragment=(Fragment)fragments.instantiateItem(content,index);
        fragments.setPrimaryItem(content,0,fragment);
        fragments.finishUpdate(content);


    }

    @Override
    protected void onStart() {
        super.onStart();
        Botton_bar.check(R.id.radioButton1);
    }

    FragmentPagerAdapter fragments=new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return 4;
        }
        @Override
        public Fragment getItem(int arg0) {
            Fragment fragment=null;
            switch (arg0){
                case 0:
                    fragment=new fragmentIndex();
                    break;
                case 1:
                    fragment=new fragmentNearby();
                    break;
                case 2:
                    fragment=new fragmentMy();
                    break;
                case 3:
                    fragment=new fragmentMore();
                    break;
                default:
                    fragment=new fragmentIndex();
                    break;
            }
            return fragment;
        }


    };

}
